﻿using System;
using System.Custom.Generic;
using Gizmox.WebGUI.Forms;

namespace CoCoon.Forms.Ribbon
{
    public class RibbonBarSearchItem : RibbonBarTextBoxItem
    {
        public SearchTextBox SearchTextBox { get; private set; }

        public event EventHandler<EventArgs<string>> Search; 

        protected virtual void OnSearch(EventArgs<string> e)
        {
            EventHandler<EventArgs<string>> handler = Search;
            if (handler != null) handler(this, e);
        }

        public event EventHandler Clear
        {
            add { SearchTextBox.Clear += value; }
            remove { SearchTextBox.Clear -= value; }
        }

        public string WatermarkText
        {
            get { return SearchTextBox.WatermarkText; }
            set { SearchTextBox.WatermarkText = value; }
        }

        protected override Control CreateControl()
        {
            SearchTextBox = new SearchTextBox();
            SearchTextBox.Search += SearchTextBoxSearch;
            return (Control)SearchTextBox;
        }

        void SearchTextBoxSearch(object sender, EventArgs e)
        {
            OnSearch(new EventArgs<string>(SearchTextBox.Text));
        }

        public bool IsSearchActive
        {
            get { return SearchTextBox.IsSearchActive; }
        }
    }
}